﻿/*************************************************************************
* Copyright(c) 2020 - Present ShenZhen EscopeTech

* ShenZhen EscopeTech Incoperated CONFIDENTIAL
* ________________________________________________________________________
*
* [2020] - Present ShenZhen EscopeTech Incoperated
* All Rights Reserved.
*
* NOTICE: All information contained herein is, and remains
* the property of ShenZhen EscopeTech Incoperated and its suppliers,
* if any. The intellectual and technical concepts contained
* herein are proprietary to ShenZhen EscopeTech Incoperated
* and its suppliers and may be covered by P.R.C. and Foreign Patents,
* patents in process, and are protected by trade secret or copyright law.
* Dissemination of this information or reproduction of this material
* is strictly forbidden unless prior written permission is obtained
* from ShenZhen EscopeTech Incoperated.
*
*************************************************************************/

#ifndef DTimeElapse_H
#define DTimeElapse_H

#include <chrono>
#include <iostream>
#include <ratio>

class DTimeElapse
{
public:
    typedef std::chrono::duration<double> dseconds;
    typedef std::chrono::duration<double, std::ratio<60> > dminutes;
    typedef std::chrono::duration<double, std::ratio<3600> > dhours;

    DTimeElapse()
        : m_begin(std::chrono::steady_clock::now())
    {
    }
    void reset() { m_begin = std::chrono::steady_clock::now(); }

    void addMSecond(const int64_t& nMs)
    {
        m_begin = m_begin + std::chrono::milliseconds(nMs);
    }

    int64_t elapsedMs() const
    {
        return std::chrono::duration_cast<std::chrono::milliseconds>(
                   std::chrono::steady_clock::now() - m_begin)
            .count();
    }

    // second
    double elapsedS() const
    {
        return std::chrono::duration_cast<dseconds>(
                   std::chrono::steady_clock::now() - m_begin)
            .count();
    }

    double elaspedH() const
    {
        return std::chrono::duration_cast<dhours>(
                   std::chrono::steady_clock::now() - m_begin)
            .count();
    }

    bool operator==(const DTimeElapse& ptr) = delete;
    bool operator!=(const DTimeElapse& ptr) = delete;

private:
    std::chrono::time_point<std::chrono::steady_clock> m_begin;
};

#endif
